<%--
  Created by IntelliJ IDEA.
  User: 25326
  Date: 2024/9/11
  Time: 14:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>添加商品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="Goods">

    <div class="layui-form-item">
        <label class="layui-form-label required">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="PName" lay-verify="required" lay-reqtext="商品名称不能为空" placeholder="请输入商品名称" value="" class="layui-input">
            <tip>商品名称</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">商品类型</label>
        <div class="layui-input-block">
            <select name="PType" lay-filter="collegeName" required>
                <option value="">--请选择--</option>
                <option value="女装男装" selected>女装男装</option>
                <option value="鞋类箱包">鞋类箱包</option>
                <option value="护肤彩妆">护肤彩妆</option>
                <option value="汇吃美食">汇吃美食</option>
                <option value="手机数码">手机数码</option>
                <option value="其他产品">其他产品</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">商品库存</label>
        <div class="layui-input-block">
            <input type="text" name="PNum" lay-verify="required" lay-reqtext="商品库存不能为空" placeholder="请输入商品库存" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">商品价格</label>
        <div class="layui-input-block">
            <input type="text" name="PPrice" lay-verify="required" lay-reqtext="商品价格不能为空" placeholder="请输入商品价格" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">商家Id</label>
        <div class="layui-input-block">
            <input type="text" name="MId" lay-verify="required" lay-reqtext="商家Id不能为空" placeholder="请输入商家Id" value="" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {

        var layer = layui.layer;
        var $ = layui.$;
        var form = layui.form;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var data = JSON.stringify(data.field);
            var formData = form.val('Goods');
            var PName = formData['PName'];
            $.post('${pageContext.request.contextPath}/ShopServlet?method=addGoods',{"data":data},function(data){
                console.log(data); // 调试：打印服务器返回的数据
                if(data==1){
                    layer.msg('添加成功',{icon:1},function(){
                        //跳转页面
                        window.location.href = "upload.jsp?PName=" +PName;
                    })
                } else {
                    layer.msg('添加失败',{icon:2});
                }
            },"json");

            return false;
        });

    });
</script>
</body>
</html>
